/*
 * Copyright (c) 2021, 2022, yzfh.cn All rights reserved.
 *
 */
package com.ly.anno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

/**
 * @author yzfh
 * @Date 2022/02/21 星期一 14:32:07
 */
@Component("myAspect")
@Aspect //标注当前MyAspect是一个切面类
@EnableAspectJAutoProxy
public class MyAspectTwo {

    //配置前置通知
    //@Before("execution(* com.ly.anno.*.*(..))")
    public void before() {
        System.out.println("前置增强......");
    }

    public void afterReturning() {
        System.out.println("后置增强......");
    }

    //proceedingJoinPoint:正在执行的连接到====切点
    //@Around("execution(* com.ly.anno.*.*(..))")
    @Around("pointCut()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("环绕前增强......");
        Object proceed = pjp.proceed(); //切点方法
        System.out.println("环绕后增强......");
        return proceed;
    }

    public void afterThrowing() {
        System.out.println("异常抛出增强......");
    }

    //@After("execution(* com.ly.anno.*.*(..))")
    @After("com.ly.anno.MyAspectTwo.pointCut()")
    public void after() {
        System.out.println("最终增强......");
    }

    //定义切点表达式
    @Pointcut("execution(* com.ly.anno.*.*(..))")
    public void pointCut() {}

}
